﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace MetaHeuristics.Aco.Collections
{
    public sealed class DaemonActionCollection : BaseAcoComponent,
        ICollection<IDaemonAction>,
        IEnumerable<IDaemonAction>
    {
        private List<IDaemonAction> list = new List<IDaemonAction>();

        public void Act()
        {
            foreach (IDaemonAction daemon in this.list)
                daemon.Act();
        }

        public void Add(IDaemonAction action)
        {
            action.Aco = this.Aco;
            list.Add(action);
        }

        public bool Remove(IDaemonAction action)
        {
            action.Aco = null;
            return list.Remove(action);
        }

        #region ICollection<IDaemonAction>
        public int Count
        {
            get
            {
                return this.list.Count;
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return false;
            }
        }

        public bool Contains(IDaemonAction daemon)
        {
            return this.list.Contains(daemon);
        }

        public void Clear()
        {
            foreach (IDaemonAction daemon in this.list)
                daemon.Aco = null;
            this.list.Clear();
        }

        public void CopyTo(IDaemonAction[] array, int index)
        {
            this.list.CopyTo(array, index);
        }
        #endregion

        #region IEnumerator<IDaemonAction>
        public IEnumerator<IDaemonAction> GetEnumerator()
        {
            return this.list.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
        #endregion
    }
}
